<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:g="http://giava.by/common/base"
	template="/WEB-INF/layout/t.xhtml">

	<ui:define name="title">
		<h:outputText value="Gestione Pubblicazioni" />
	</ui:define>
	<ui:define name="roles">
		<f:attribute name="roles" value="exhibition" />
	</ui:define>

	<ui:define name="content">

		<h:form enctype="multipart/form-data">

			<p:messages id="messages" />
			<center>
				<p:panel header="Gestione Pubblicazioni">

					<h:panelGrid columns="2" style="width: 95%">
						<h:outputLabel for="title" style="font-weight: bolder;"
							value="Titolo: " />
						<h:outputText id="title"
							value="#{publicationController.element.title}" />

						<h:outputLabel for="exhibition" style="font-weight: bolder;"
							value="Esposizione: " />
						<h:outputText id="exhibition"
							value="#{publicationController.element.exhibition.name}"
							width="640px" />

						<h:outputLabel for="preview" style="font-weight: bolder;"
							value="Anteprima: " />
						<h:outputText id="preview"
							value="#{publicationController.element.preview}" />

					</h:panelGrid>
					<br />
				</p:panel>
				<br />
				<p:panel header="Caricamento Documenti e Immagini">
					<p:fileUpload id="imgUp" mode="advanced" multiple="true"
						sizeLimit="20000000"
						fileUploadListener="#{publicationController.handleUpload}"
						label="Scegli Immagine o Documento"
						description="Scegli Immagine o Documento"
						update="imgList, docList" />
				</p:panel>
				<br />
				<p:dataTable id="imgList" var="img"
					value="#{publicationController.element.images}"
					rowIndexVar="index2">
					<f:facet name="header">Immagini</f:facet>
					<p:column>
						<f:facet name="header">ind</f:facet>
						<h:outputText value="#{index2+1}" />
					</p:column>
					<p:column>
						<f:facet name="header">foto</f:facet>
						<h:graphicImage value="/img/#{img.filename}"
							width="#{g:imageWidthProportionalUrl('img/'.concat(img.filename),100,100)}"
							height="#{g:imageHeightProportionalUrl('img/'.concat(img.filename), 100, 100)}"
							alt="#{img.filename}" title="#{img.filename}"
							style="padding: 5px;" />
					</p:column>
					<p:column>
						<f:facet name="header">nome</f:facet>
						<h:outputText value="#{img.filename}" />
					</p:column>

					<p:column>
						<f:facet name="header">elimina</f:facet>
						<g:center>
							<h:commandLink
								action="#{publicationController.removeImage(img.id)}"
								value="elimina" immediate="true"
								onclick="if (!confirm('Vuoi davvero eliminare?')) return false"
								rendered="#{not empty img.id}" />
						</g:center>
					</p:column>
				</p:dataTable>
				<br />
				<p:dataTable id="docList" var="doc"
					value="#{publicationController.element.documents}"
					rowIndexVar="index">
					<f:facet name="header">Documenti</f:facet>
					<p:column>
						<f:facet name="header">ind</f:facet>
						<h:outputText value="#{index}" />
					</p:column>
					<p:column>
						<f:facet name="header">nome</f:facet>
						<h:outputText value="#{doc.filename}" />
					</p:column>

					<p:column>
						<f:facet name="header">elimina</f:facet>
						<g:center>
							<h:commandLink
								action="#{publicationController.removeDocument(doc.id)}"
								value="elimina" immediate="true"
								onclick="if (!confirm('Vuoi davvero eliminare?')) return false"
								rendered="#{not empty doc.id}" />
						</g:center>
					</p:column>
				</p:dataTable>
				<h:panelGrid columns="4">

					<h:commandButton action="#{publicationController.save}"
						value="Salva" immediate="false"
						rendered="#{not publicationController.editMode}" />

					<h:commandButton action="#{publicationController.update}"
						value="Salva le modifiche" immediate="false"
						rendered="#{publicationController.editMode}" />

				</h:panelGrid>
			</center>
		</h:form>

	</ui:define>
</ui:composition>